//
//  ECProfileSelfTruenameVc.m
//  Edu_iOS2018
//
//  Created by apple on 2018/1/19.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#define Textfield_height        960*0.1406         //封装输入框的高度

#import "ECProfileSelfTruenameVc.h"
#import "ECUITextField_Account.h"

@interface ECProfileSelfTruenameVc (){
    ECUITextField_Account *uitf_name;
    ECUButton *loginBtn;
}

@end

@implementation ECProfileSelfTruenameVc

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"姓名";
    
    uitf_name = [[ECUITextField_Account alloc]initWithFrame:CGRectMake(kProportion_Width(60), kProportion_Width(60), kScreenWidth - kProportion_Width(MarginLeft_Textfield*2) , kProportion_Height(Textfield_height)) placeholder:@"" leftImage:[UIImage imageNamed:@"registered_userName"]];
    uitf_name.textField.text = self.name;
    [self.view addSubview:uitf_name];
    [uitf_name.textField becomeFirstResponder];
    
    // login btn
    loginBtn = [ECUButton buttonWithType:UIButtonTypeCustom];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"flatButton_colorNormal"] forState:UIControlStateNormal];
    loginBtn.frame = CGRectMake(kProportion_Width(60), CGRectGetMaxY(uitf_name.frame) + kProportion_Height(MarginHeight_textfield), kScreenWidth - kProportion_Width(60*2),(kScreenWidth - kProportion_Width(60*2))* 0.1406);
    [loginBtn addTarget:self action:@selector(getDataWithURL) forControlEvents:UIControlEventTouchUpInside];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"flatButton_colorSelected"] forState:UIControlStateHighlighted];
    [loginBtn setTitle:@"确定" forState:UIControlStateNormal];
    loginBtn.titleLabel.font = [UIFont systemFontOfSize:ceil(20)];
    [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [self.view addSubview:loginBtn];
}

-(void)getDataWithURL{
    DLog(@"%@",[[UserInfoManager shareUser] token]);
    [HWHttpTool requestWithMethod:@"POST"
                              url:URL_POST_MeSetting
                           params:@{@"value":uitf_name.textField.text,
                                    @"field":@"truename"
                                    }
                          headers:@{@"X-AUTH-TOKEN":[[UserInfoManager shareUser] token]}
                          success:^(id json) {
                              DLog(@"%@",json);
                              [MBProgressHUD showTipMessageInWindow:@"姓名更新成功"];
                              [self.navigationController popViewControllerAnimated:YES];
                          }
                          failure:^(NSError *error) {
                              NSString *str = [ECData_Json requestErrorTipWith:error];
                              DLog(@"%@",str);
                              if (!([str isEqualToString:@"101"] || [str isEqualToString:@"401"])) {
                                  [MBProgressHUD showTipMessageInWindow:str];
                              }
                          }];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing: YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
